package com.atguigu.tingshu.order.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.CoordinateUtil;
import cn.hutool.core.util.IdUtil;
import com.atguigu.tingshu.account.AccountFeignClient;
import com.atguigu.tingshu.album.AlbumFeignClient;
import com.atguigu.tingshu.common.constant.RedisConstant;
import com.atguigu.tingshu.common.constant.SystemConstant;
import com.atguigu.tingshu.common.execption.GuiguException;
import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import com.atguigu.tingshu.common.rabbit.service.RabbitService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.model.order.OrderDerate;
import com.atguigu.tingshu.model.order.OrderDetail;
import com.atguigu.tingshu.model.order.OrderInfo;
import com.atguigu.tingshu.model.user.VipServiceConfig;
import com.atguigu.tingshu.order.helper.SignHelper;
import com.atguigu.tingshu.order.mapper.OrderDerateMapper;
import com.atguigu.tingshu.order.mapper.OrderDetailMapper;
import com.atguigu.tingshu.order.mapper.OrderInfoMapper;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.user.client.UserFeignClient;
import com.atguigu.tingshu.vo.account.AccountDeductVo;
import com.atguigu.tingshu.vo.order.OrderDerateVo;
import com.atguigu.tingshu.vo.order.OrderDetailVo;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import com.atguigu.tingshu.vo.order.TradeVo;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@Slf4j
@Service
@SuppressWarnings({"all"})
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {

    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @Autowired
    private UserFeignClient userFeignClient;

    @Autowired
    private AlbumFeignClient albumFeignClient;


    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private OrderDetailMapper orderDetailMapper;

    @Autowired
    private OrderDerateMapper orderDerateMapper;

    @Autowired
    private AccountFeignClient accountFeignClient;

    @Autowired
    private RabbitService rabbitService;


    /**
     * 订单结算
     *
     * @param tradeVo 包含：项目类型、项目ID、声音数量
     * @return
     */
    @Override
    public OrderInfoVo tradeData(Long userId, TradeVo tradeVo) {
        //1.创建订单VO响应对象
        OrderInfoVo orderInfoVo = new OrderInfoVo();

        //1.1.初始化相关三个金额：原价、订单价、减免价格 TODO 这里价格信息必须是字符串"0.00"
        BigDecimal originalAmount = new BigDecimal("0.00");
        BigDecimal orderAmount = new BigDecimal("0.00");
        BigDecimal derateAmount = new BigDecimal("0.00");

        //1.2.初始化商品列表跟优惠列表
        List<OrderDetailVo> orderDetailVoList = new ArrayList<>();
        List<OrderDerateVo> orderDerateVoList = new ArrayList<>();

        //付款项目类型: 1001-专辑 1002-声音 1003-vip会员
        String itemType = tradeVo.getItemType();
        //2.处理购买项目类型为VIP会员
        if (SystemConstant.ORDER_ITEM_TYPE_VIP.equals(itemType)) {
            //2.1 远程调用用户服务获取用户选择套餐信息
            VipServiceConfig vipServiceConfig = userFeignClient.getVipServiceConfigById(tradeVo.getItemId()).getData();
            Assert.notNull(vipServiceConfig, "用户{}选购套餐{}不存在", userId, tradeVo.getItemId());
            //2.2 计算"商品"相关价格
            originalAmount = vipServiceConfig.getPrice();
            orderAmount = vipServiceConfig.getDiscountPrice();
            //判断是否有减免
            if (originalAmount.compareTo(orderAmount) == 1) {
                derateAmount = originalAmount.subtract(orderAmount);
                OrderDerateVo orderDerateVo = new OrderDerateVo();
                //订单减免类型 1405-专辑折扣 1406-VIP服务折
                orderDerateVo.setDerateType(SystemConstant.ORDER_DERATE_VIP_SERVICE_DISCOUNT);
                orderDerateVo.setDerateAmount(derateAmount);
                orderDerateVo.setRemarks("VIP限时优惠价：" + derateAmount);
                orderDerateVoList.add(orderDerateVo);
            }
            //2.3 封装商品明细及优惠明细列表
            OrderDetailVo orderDetailVo = new OrderDetailVo();
            orderDetailVo.setItemId(tradeVo.getItemId());
            orderDetailVo.setItemName("VIP套餐：" + vipServiceConfig.getName());
            orderDetailVo.setItemUrl(vipServiceConfig.getImageUrl());
            orderDetailVo.setItemPrice(originalAmount);
            orderDetailVoList.add(orderDetailVo);
        } else if (SystemConstant.ORDER_ITEM_TYPE_ALBUM.equals(itemType)) {
            //3.处理购买项目类型为专辑
            //3.1 远程调用用户服务，判断当前用户是否购买过当前专辑
            Long albumId = tradeVo.getItemId();
            Boolean flag = userFeignClient.isPaidAlbum(albumId).getData();
            if (flag) {
                throw new RuntimeException("用户已购买过当前专辑，不能重复购买");
            }
            //3.2 远程调用专辑服务获取专辑信息，得到价格跟折扣信息
            AlbumInfo albumInfo = albumFeignClient.getAlbumInfo(albumId).getData();
            Assert.notNull(albumInfo, "专辑{}不存在", albumId);
            //3.2.1 获取专辑价格
            originalAmount = albumInfo.getPrice();
            orderAmount = originalAmount;
            //3.2.2 获取专辑折扣
            BigDecimal discount = albumInfo.getDiscount();
            BigDecimal vipDiscount = albumInfo.getVipDiscount();

            //3.3 远程调用用户服务获取用户身份
            UserInfoVo userInfoVo = userFeignClient.getUserInfoVo(userId).getData();
            Boolean isVIP = false;
            if (userInfoVo.getIsVip().intValue() == 1 && userInfoVo.getVipExpireTime().after(new Date())) {
                isVIP = true;
            }
            //3.4 计算相关价格：
            //3.4.1 判断是普通用户且有专辑设置用户折扣 不打折 -1
            if (!isVIP && discount.intValue() != -1) {
                //订单价=原价*折扣
                orderAmount = originalAmount.multiply(discount).divide(BigDecimal.valueOf(10), 2, BigDecimal.ROUND_HALF_UP);
                derateAmount = originalAmount.subtract(orderAmount);
            }
            //3.4.2 判断是VIP用户且专辑设置VIP会员折扣
            if (isVIP && vipDiscount.intValue() != -1) {
                //订单价=原价*折扣
                orderAmount = originalAmount.multiply(vipDiscount).divide(BigDecimal.valueOf(10), 2, BigDecimal.ROUND_HALF_UP);
                derateAmount = originalAmount.subtract(orderAmount);
            }
            //3.5 封装商品明细及优惠明细列表
            OrderDetailVo orderDetailVo = new OrderDetailVo();
            orderDetailVo.setItemId(albumId);
            orderDetailVo.setItemName("专辑：" + albumInfo.getAlbumTitle());
            orderDetailVo.setItemUrl(albumInfo.getCoverUrl());
            orderDetailVo.setItemPrice(originalAmount);
            orderDetailVoList.add(orderDetailVo);

            if (originalAmount.compareTo(orderAmount) == 1) {
                OrderDerateVo orderDerateVo = new OrderDerateVo();
                orderDerateVo.setDerateType(SystemConstant.ORDER_DERATE_ALBUM_DISCOUNT);
                orderDerateVo.setDerateAmount(derateAmount);
                orderDerateVo.setRemarks("专辑减免价格：" + derateAmount);
                orderDerateVoList.add(orderDerateVo);
            }
        } else if (SystemConstant.ORDER_ITEM_TYPE_TRACK.equals(itemType)) {
            //4.TODO 处理购买项目类型为声音
            //4.1 远程调用专辑服务获取用户待购买声音列表-将声音列表作为待结算商品展示到结算页
            Long trackId = tradeVo.getItemId();
            Integer trackCount = tradeVo.getTrackCount();
            List<TrackInfo> trackInfoList = albumFeignClient.getwaitPayTrackInfoList(trackId, trackCount).getData();
            Assert.notNull(trackInfoList, "不满足待结算声音");

            //4.2 远程调用专辑服务获取专辑信息，得到价格。声音不支持折扣
            AlbumInfo albumInfo = albumFeignClient.getAlbumInfo(trackInfoList.get(0).getAlbumId()).getData();
            //获取专辑中设置单集价格
            BigDecimal price = albumInfo.getPrice();

            //4.3 计算相关价格：原价=订单价
            originalAmount = price.multiply(BigDecimal.valueOf(trackInfoList.size()));
            orderAmount = originalAmount;

            //4.4 封装商品明细列表即可
            orderDetailVoList = trackInfoList
                    .stream()
                    .map(trackInfo -> {
                        OrderDetailVo orderDetailVo = new OrderDetailVo();
                        orderDetailVo.setItemId(trackInfo.getId());
                        orderDetailVo.setItemName("声音：" + trackInfo.getTrackTitle());
                        orderDetailVo.setItemUrl(trackInfo.getCoverUrl());
                        orderDetailVo.setItemPrice(price);
                        return orderDetailVo;
                    }).collect(Collectors.toList());
        }

        //5.响应订单VO对象
        //5.1封装订单VO中价格相关属性
        orderInfoVo.setOriginalAmount(originalAmount);
        orderInfoVo.setOrderAmount(orderAmount);
        orderInfoVo.setDerateAmount(derateAmount);
        //5.2封装订单VO中商品相关两个列表
        orderInfoVo.setOrderDetailVoList(orderDetailVoList);
        orderInfoVo.setOrderDerateVoList(orderDerateVoList);
        //5.3 封装其他属性-项目购买类型、本次订单确认流水号、时间戳及签名
        //5.3.1 防止订单利用浏览器回退造成订单重复提交，生成唯一流水号值
        String key = RedisConstant.ORDER_TRADE_NO_PREFIX + userId;
        String tradeNo = IdUtil.randomUUID();
        //5.3.2 将本次订单流水号值存入Redis 中，并设置过期时间：5分钟
        redisTemplate.opsForValue().set(key, tradeNo, 5, TimeUnit.MINUTES);
        //5.3.3 封装OrderInfoVO中返回给客户端
        orderInfoVo.setTradeNo(tradeNo);
        //5.4 封装订单中项目类型
        orderInfoVo.setItemType(itemType);
        //5.5 封装时间戳及签名
        orderInfoVo.setTimestamp(System.currentTimeMillis());
        //5.5.1 将订单VO转为Map TODO 结算页无法确定用户支付方式，将付款方式payWay去掉不需要参与加签规则
        Map<String, Object> map = BeanUtil.beanToMap(orderInfoVo, false, true);
        //5.5.2 将订单Map转为签名
        String sign = SignHelper.getSign(map);
        orderInfoVo.setSign(sign);
        return orderInfoVo;
    }

    /**
     * 订单提交（包含两种付款方式1.余额 2.微信）
     *
     * @param orderInfoVo
     * @return
     */
    @Override
    @GlobalTransactional(rollbackFor = Exception.class)
    public Map<String, String> submitOrder(OrderInfoVo orderInfoVo, Long userId) {
        //1.业务校验：校验流水号是否相同 避免用户通过小程序回退按钮造成重复提交订单
        //1.1 获取Redis中流水号值跟前端确认页流式号值比较
        String key = RedisConstant.ORDER_TRADE_NO_PREFIX + userId;
        //1.2 如果二者不同则业务终止，如果相同删除Redis流水号业务继续
        //1.3 执行lua脚本完成判断
        //1.3.1 定义lua脚本
        String script = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end";
        //1.3.2 创建脚本对象封装lua脚本
        DefaultRedisScript<Boolean> redisScript = new DefaultRedisScript<>(script, Boolean.class);
        Boolean flag = (Boolean) redisTemplate.execute(redisScript, Arrays.asList(key), orderInfoVo.getTradeNo());
        if (!flag) {
            throw new GuiguException(500, "流水号验证失败");
        }
        //2.业务校验：校验签名是否是否一致 避免订单确认页篡改订单相关信息
        //2.1 将订单VO转为Map TODO 订单结算页生成签名时候，payWay并未参与加签 验签之前，将Map中payWay去掉
        Map<String, Object> map = BeanUtil.beanToMap(orderInfoVo);
        map.remove("payWay");
        //2.2 调用签名工具类完成签名验证
        SignHelper.checkSign(map);

        //3.核心业务1：保存订单相关信息 未支付状态
        OrderInfo orderInfo = this.saveOrderInfo(orderInfoVo, userId);
        //支付方式：1101-微信 1102-支付宝 1103-账户余额
        String payWay = orderInfoVo.getPayWay();
        //4. 判断付款方式-如果是余额，则需要扣减余额，扣减成功完成订单状态改为已支付且完成虚拟物品发货
        if (SystemConstant.ORDER_PAY_ACCOUNT.equals(payWay)) {
            //4.1 远程调用账户服务完成余额扣减 发生异常则进行全局异常回滚
            //4.1.1 构建扣减余额VO对象
            AccountDeductVo accountDeductVo = new AccountDeductVo();
            accountDeductVo.setOrderNo(orderInfo.getOrderNo());
            accountDeductVo.setUserId(orderInfo.getUserId());
            accountDeductVo.setAmount(orderInfo.getOrderAmount());
            accountDeductVo.setContent(orderInfo.getOrderTitle());
            Result result = accountFeignClient.checkAndDeduct(accountDeductVo);
            //4.1.2 一定要判断远程调用结果业务状态码是否为200，如果不是200说明远程调用失败，触发全局事务回滚
            if (result.getCode().intValue() != 200) {
                throw new GuiguException(500, "余额扣减失败");
            }
            //4.2 余额扣减成功，将订单状态改为:已支付
            orderInfo.setOrderStatus(SystemConstant.ORDER_STATUS_PAID);
            orderInfoMapper.updateById(orderInfo);

            //4.3 余额扣减成功，远程调用用户服务完成虚拟物品发货
            //4.3.1 创建虚拟物品发货VO对象
            UserPaidRecordVo userPaidRecordVo = new UserPaidRecordVo();
            userPaidRecordVo.setOrderNo(orderInfo.getOrderNo());
            userPaidRecordVo.setUserId(orderInfo.getUserId());
            userPaidRecordVo.setItemType(orderInfo.getItemType());
            //4.3.2 封装购买项目ID列表 有可能是会员或者专辑或者声音 ID
            List<OrderDetailVo> orderDetailVoList = orderInfoVo.getOrderDetailVoList();
            if (CollectionUtil.isNotEmpty(orderDetailVoList)) {
                List<Long> itemIdList = orderDetailVoList.stream().map(OrderDetailVo::getItemId).collect(Collectors.toList());
                userPaidRecordVo.setItemIdList(itemIdList);
            }
            //4.3.3 远程调用用户服务完成虚拟物品发货
            result = userFeignClient.savePaidRecord(userPaidRecordVo);
            if (result.getCode().intValue() != 200) {
                throw new GuiguException(500, "虚拟物品发货异常");
            }
        } else if (SystemConstant.ORDER_PAY_WAY_WEIXIN.equals(payWay)) {
            //5. 判断付款方式-如果是微信，避免用户超时未支付，故发送延迟消息完成延迟关单
            rabbitService.sendDelayMessage(MqConst.EXCHANGE_CANCEL_ORDER, MqConst.ROUTING_CANCEL_ORDER, orderInfo.getId(), MqConst.CANCEL_ORDER_DELAY_TIME);
        }
        //6.响应Map封装订单编号
        String orderNo = orderInfo.getOrderNo();
        Map<String, String> result = new HashMap<>();
        result.put("orderNo", orderNo);
        return result;
    }

    /**
     * 保存订单
     *
     * @param orderInfoVo 订单VO
     * @param userId      用户ID
     * @return
     */
    @Override
    public OrderInfo saveOrderInfo(OrderInfoVo orderInfoVo, Long userId) {
        //1.保存订单，得到订单ID
        //1.1 将提交订单VO转为订单PO对象
        OrderInfo orderInfo = BeanUtil.copyProperties(orderInfoVo, OrderInfo.class);
        //1.2 手动为其他属性赋值
        //1.2.1 用户ID
        orderInfo.setUserId(userId);
        //1.2.2 订单状态，未支付 0901-未支付 0902-已支付 0903-已取消
        orderInfo.setOrderStatus(SystemConstant.ORDER_STATUS_UNPAID);
        //1.2.3 订单标题，从订单明细中第一条购买项目中获取
        List<OrderDetailVo> orderDetailVoList = orderInfoVo.getOrderDetailVoList();
        if (CollectionUtil.isNotEmpty(orderDetailVoList)) {
            String itemName = orderDetailVoList.get(0).getItemName();
            orderInfo.setOrderTitle(itemName);
        }
        //1.2.4 订单编号 商户系统中全局唯一 形式：订单日期+雪花算法(分布式ID生成器)
        String orderNo = DateUtil.today().replaceAll("-", "") + IdUtil.getSnowflakeNextId();
        orderInfo.setOrderNo(orderNo);
        //1.3 保存订单，得到订单ID
        orderInfoMapper.insert(orderInfo);
        Long orderId = orderInfo.getId();

        //2.保存订单明细,将订单明细关联订单ID
        if (CollectionUtil.isNotEmpty(orderDetailVoList)) {
            orderDetailVoList
                    .stream()
                    .forEach(orderDetailVo -> {
                        OrderDetail orderDetail = BeanUtil.copyProperties(orderDetailVo, OrderDetail.class);
                        orderDetail.setOrderId(orderId);
                        orderDetailMapper.insert(orderDetail);
                    });
        }
        //3.保存优惠明细,将优惠明细关联订单ID
        List<OrderDerateVo> orderDerateVoList = orderInfoVo.getOrderDerateVoList();
        if (CollectionUtil.isNotEmpty(orderDerateVoList)) {
            orderDerateVoList
                    .stream()
                    .forEach(orderDerateVo -> {
                        OrderDerate orderDerate = BeanUtil.copyProperties(orderDerateVo, OrderDerate.class);
                        orderDerate.setOrderId(orderId);
                        orderDerateMapper.insert(orderDerate);
                    });
        }
        return orderInfo;
    }

    /**
     * 获取订单详情
     *
     * @param orderNo
     * @return
     */
    @Override
    public OrderInfo getOrderInfo(String orderNo) {
        //1.根据订单编号查询订单信息
        LambdaQueryWrapper<OrderInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OrderInfo::getOrderNo, orderNo);
        OrderInfo orderInfo = orderInfoMapper.selectOne(queryWrapper);
        Assert.notNull(orderInfo, "订单不存在");

        //2.根据订单ID查询订单明细列表
        LambdaQueryWrapper<OrderDetail> detailLambdaQueryWrapper = new LambdaQueryWrapper<>();
        detailLambdaQueryWrapper.eq(OrderDetail::getOrderId, orderInfo.getId());
        List<OrderDetail> orderDetailList = orderDetailMapper.selectList(detailLambdaQueryWrapper);
        orderInfo.setOrderDetailList(orderDetailList);

        //3.根据订单ID查询订单优惠列表
        LambdaQueryWrapper<OrderDerate> derateLambdaQueryWrapper = new LambdaQueryWrapper<>();
        derateLambdaQueryWrapper.eq(OrderDerate::getOrderId, orderInfo.getId());
        List<OrderDerate> orderDerateList = orderDerateMapper.selectList(derateLambdaQueryWrapper);
        orderInfo.setOrderDerateList(orderDerateList);
        return orderInfo;
    }

    /**
     * 分页获取当前用户订单列表
     *
     * @param page
     * @param limit
     * @return
     */
    @Override
    public Page<OrderInfo> getUserOrderByPage(Page<OrderInfo> pageInfo, Long userId) {
        //方式一：分页查询订单列表，遍历订单再获取订单明细
        //1.查询订单列表
        //LambdaQueryWrapper<OrderInfo> queryWrapper = new LambdaQueryWrapper<>();
        //queryWrapper.eq(OrderInfo::getUserId, userId);
        //queryWrapper.orderByAsc(OrderInfo::getId);
        //pageInfo = orderInfoMapper.selectPage(pageInfo, queryWrapper);
        ////2.遍历订单中获取订单中明细列表
        //pageInfo.getRecords().forEach(orderInfo -> {
        //    List<OrderDetail> orderDetailList = this.getOrderDetailList(orderInfo.getId());
        //    orderInfo.setOrderDetailList(orderDetailList);
        //});
        //return pageInfo;
        //方式二：通过动态SQL查询订单及订单明细
        return orderInfoMapper.getUserOrderByPage(pageInfo, userId);
    }

    /**
     * 根据订单状态，如果是未支付将订单关闭
     *
     * @param orderId
     */
    @Override
    public void cancelOrder(Long orderId) {
        //1.根据订单ID查询订单状态 判断状态
        OrderInfo orderInfo = orderInfoMapper.selectById(orderId);
        if (orderInfo != null) {
            //2.如果订单是未支付，将订单修改为关闭
            String orderStatus = orderInfo.getOrderStatus();
            if (SystemConstant.ORDER_STATUS_UNPAID.equals(orderStatus)) {
                orderInfo.setOrderStatus(SystemConstant.ORDER_STATUS_CANCEL);
                orderInfoMapper.updateById(orderInfo);
            }
        }
    }

    /**
     * 用户微信支付成功后，修改订单状态且完成虚拟物品发货
     *
     * @param orderNo
     * @return
     */
    @Override
    public void orderPaySuccess(String orderNo) {
        //1.根据订单编号查询订单信息 判断订单状态
        OrderInfo orderInfo = this.getOrderInfo(orderNo);
        String orderStatus = orderInfo.getOrderStatus();
        if (!SystemConstant.ORDER_STATUS_PAID.equals(orderStatus)) {
            //如果订单状态不是已支付，正常处理更新为已支付
            orderInfo.setOrderStatus(SystemConstant.ORDER_STATUS_PAID);
            orderInfoMapper.updateById(orderInfo);
            //2.远程调用用户服务完成虚拟物品发货
            //2.1 构建虚拟物品发货VO对象
            UserPaidRecordVo userPaidRecordVo = new UserPaidRecordVo();
            userPaidRecordVo.setOrderNo(orderNo);
            userPaidRecordVo.setUserId(orderInfo.getUserId());
            userPaidRecordVo.setItemType(orderInfo.getItemType());
            //2.2 从订单对象中获取购买商品ID
            List<OrderDetail> orderDetailList = orderInfo.getOrderDetailList();
            if (CollectionUtil.isNotEmpty(orderDetailList)) {
                List<Long> itemIdList = orderDetailList.stream().map(OrderDetail::getItemId)
                        .collect(Collectors.toList());
                userPaidRecordVo.setItemIdList(itemIdList);
            }
            Result result = userFeignClient.savePaidRecord(userPaidRecordVo);
            //2.3 判断远程调用是否成功 状态码非200，抛出异常触发全局事务回滚
            if (result.getCode().intValue() != 200) {
                throw new RuntimeException("远程虚拟物品发货调用失败");
            }
        }

    }

    /**
     * 根据订单ID查询订单明细列表
     *
     * @param orderId
     * @return
     */
    private List<OrderDetail> getOrderDetailList(Long orderId) {
        LambdaQueryWrapper<OrderDetail> detailLambdaQueryWrapper = new LambdaQueryWrapper<>();
        detailLambdaQueryWrapper.eq(OrderDetail::getOrderId, orderId);
        List<OrderDetail> orderDetailList = orderDetailMapper.selectList(detailLambdaQueryWrapper);
        return orderDetailList;
    }


}
